MediaPipeOnDeviceLlm

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

True when this backend accepts an LlmPart.Image in generate. False = text-only.

Functions

Link copied to clipboard
open suspend fun capabilities(): AiCapabilities

Honest self-report for a capability-aware caller: whether this backend genuinely streams tokens and accepts images, which GenerationConfig fields it reads, and — when it can't run — the real AiFailure reason instead of a bare false. Default answer is conservative (no streaming, no honored config) and derives AiCapabilities.unavailableReason from isAvailable alone; a backend with a more specific gate (model residency, OS feature status) overrides this to report why.

Link copied to clipboard
open suspend override fun generate(prompt: String): AiResult<String>

Runs prompt on-device. Success carries the model's text; failure names why via AiFailure.

open suspend fun generate(parts: List<LlmPart>): AiResult<String>

Multimodal entry point. Default maps a single LlmPart.Text onto generate (String) so every existing text-only actual (MediaPipe, Foundation Models, jvm) keeps working with zero changes. Backends that accept images (ML Kit GenAI) override this directly.

Link copied to clipboard
open fun generateStream(prompt: String): Flow<String>

Streaming variant of generate. Default replays the single-shot result as one emission so every existing actual keeps working with zero changes; backends with native token streaming (ML Kit GenAI, MediaPipe) override this directly. CompositeOnDeviceLlm overrides both overloads too, so streaming through it reaches whichever backend it picked, not this default.

open fun generateStream(parts: List<LlmPart>): Flow<String>
Link copied to clipboard
open override fun isAvailable(): Boolean

Cheap, synchronous floor — true only when the platform could run inference. NOT the authoritative runtime check (model residency is async); generate still guards internally.